
<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>


<div class="panel ">
	<div class="panel-body pan" style="height: 430px">
			<div class="form-body pal">
				<div class="row" style="margin-top:-15px; margin-bottom: 10px;">
					<div class="col-lg-6" style="width: 100%; float:left;">
						<label for="inputUsername" class="col-md-3 control-label">知识库
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="classesEn" class="form-control">
								<?for(class in classList){?>
									<option value="${class.nameEn}">${class.nameZh}</option>
								<?}?>
								</select>
							</div>
						</div>
					</div>
					<div class="col-lg-6" style="width: 100%; float:left; ">
						<label for="inputUsername" class="col-md-3 control-label">数据源
							<span class='require' id="mima">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
							<?for(shardingDataSource in shardingDataSourceList){?>
									<input type="checkbox" class="shardingDataSourceInput" id="shardingDataSourceId_${shardingDataSource.id}" name="shardingDataSourceId" value="${shardingDataSource.id}" />&nbsp;&nbsp;<label for="shardingDataSourceId_${shardingDataSource.id}">${shardingDataSource.nameZh}</label></label>&nbsp;&nbsp;&nbsp;
								<?}?>
							
							</div>
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">是否开启分库分表
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="openSharding" oncanplay="openShardingType(this);" class="form-control">
									<option value="0">关闭</option>
									<option value="1">开启</option>
								</select>
							</div>
						</div>
					</div>
					<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">单表记录阈值
							<span class='require' >*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="shardingThreshold" type="text" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">分表个数
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="shardingTableCount" type="text" disabled="true" class="form-control" value="1" />
							</div>
						</div>
					</div>
				</div> 	
				<input id="id" type="hidden" class="form-control" />
	</div>
</div>
<?} ?>
<script type="text/javascript">
	var shardingRepositoryDataSourceId = window.parent.getShardingRepositoryDataSourceId();
	$(function() {
		$("#id").val(shardingRepositoryDataSourceId);
		if('0' != shardingRepositoryDataSourceId){
			demo();
		}
	});
	
	function Page() {
		var value=[];
		$("input[name='shardingDataSourceId']:checked").each(function(){
			value.push($(this).val());
		});
		 if ($.trim($("#shardingThreshold").val()).length < 1) {
			alert('单表记录阈值不能为空！');
			return null;
		}
		if (value == null || value == '' || value.length < 1) {
			alert('请选择数据源！');
			return null;
		}
		 $.ajax({
			type : "post",
			url : "saveEditshardingRepositoryDataSource.do",
			data : {
				"id" : $("#id").val(),
				"classesEn" : $("#classesEn").val(),
				"value" : value,
				"openSharding" : $("#openSharding").val(),
				"shardingThreshold" : $("#shardingThreshold").val(),
				"shardingTableCount" : $("#shardingTableCount").val(),
			},
			dataType : "json",
			traditional : true,
			async: false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name); 
          		window.parent.getShardingRepositoryDataSource('0');
				if(data[0] == 'yes'){
					parent.layer.msg('提交成功');
				}else{
					parent.layer.msg('提交失败');
				}
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		}); 
	}
	function demo() {
		$.ajax({
			type : "post",
			url : "findShardingRepositoryDataSource.do",
			data : {
				"id" : shardingRepositoryDataSourceId,
			},
			dataType : "json",
			async : false,
			success : function(data) {
				$("#id").val(data[0].id);
				$("#classesEn").val(data[0].classesEn);
				$("#openSharding").val(data[0].openSharding);
				if(data[0].openSharding == '1'){
					$("#shardingTableCount").removeAttr("disabled");
				}
				$("#shardingThreshold").val(data[0].shardingThreshold);
				$("#shardingTableCount").val(data[0].shardingTableCount);
				
				$("input[name=shardingDataSourceId]").each(function(){
					if($(this).val() == data[0].shardingDataSourceId){
						$(this).parents('.icheckbox_minimal-grey').addClass('checked');
						$(this).prop("checked", "true");
					}
				});
				$(".shardingDataSourceInput").attr("disabled","true");
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	};
	$("select#openSharding").change(function(){
	    if($(this).val() == '0'){
	    	$("#shardingTableCount").attr("disabled","true");
	    }else{
	    	$("#shardingTableCount").removeAttr("disabled");
	    }
	});
</script>


